import {designPage} from "@peryl/react-compose";
import {useTableOption} from "../../modules/plain-design/useTableOption";
import {AutoTable, i18n, Plc, PlcCheckbox, PlcDate, PlcInput, PlcTextarea} from "plain-design";

export default designPage(() => {

  /*一级菜单*/
  const fstMenuOption = useTableOption({
    url: '/menu',
    param: {
      filters: [
        { field: "grade", value: "1", operator: "=" }
      ]
    },
    showRows: 5,
    defaultNewRow: {
      grade: '1'
    },
  });

  /*二级菜单*/
  const secMenuOption = useTableOption({
    url: '/menu',
    showRows: 5,
    /*param: {
      filters: [
        { field: "grade", value: "2", operator: "=" }
      ]
    },*/
    parentOption: fstMenuOption,
    parentMap: { parentId: 'id', parentName: 'name' },
    defaultNewRow: {
      grade: '2',
      insertFlag: 'Y',
      updateFlag: 'Y',
      deleteFlag: 'Y',
      importFlag: 'Y',
      exportFlag: 'Y',
    },
  });

  return () => <>
    <AutoTable option={fstMenuOption}>
      <PlcInput title={i18n.$intl('page.menuListPage.xxx').d('菜单名称')} field="name" required/>
      <PlcInput title={i18n.$intl('page.menuListPage.xxx').d('菜单图标')} field="icon" required/>
      <PlcDate title={i18n.$intl('page.menuListPage.xxx').d('创建时间')} field="createdAt" datetime width={175} editable={false}/>
      <PlcDate title={i18n.$intl('page.menuListPage.xxx').d('更新时间')} field="updatedAt" datetime width={175} editable={false}/>
      <PlcTextarea title={i18n.$intl('page.menuListPage.xxx').d('备注')} field="comment"/>
    </AutoTable>
    <AutoTable option={secMenuOption}>
      <PlcInput title={i18n.$intl('page.menuListPage.xxx').d('菜单名称')} field="name" required width={225}/>
      <PlcInput title={i18n.$intl('page.menuListPage.xxx').d('菜单路径')} field="path" required width={325} overflowTooltip/>
      <PlcInput title={i18n.$intl('page.menuListPage.xxx').d('菜单编码')} field="code"/>

      <PlcCheckbox title={i18n.$intl('page.menuListPage.xxx').d('可新建')} field="insertFlag" trueValue="Y" falseValue="N"/>
      <PlcCheckbox title={i18n.$intl('page.menuListPage.xxx').d('可修改')} field="updateFlag" trueValue="Y" falseValue="N"/>
      <PlcCheckbox title={i18n.$intl('page.menuListPage.xxx').d('可删除')} field="deleteFlag" trueValue="Y" falseValue="N"/>
      <PlcCheckbox title={i18n.$intl('page.menuListPage.xxx').d('可导入')} field="importFlag" trueValue="Y" falseValue="N"/>
      <PlcCheckbox title={i18n.$intl('page.menuListPage.xxx').d('可导出')} field="exportFlag" trueValue="Y" falseValue="N"/>

      <PlcDate title={i18n.$intl('page.menuListPage.xxx').d('创建时间')} field="createdAt" datetime width={175} editable={false}/>
      <PlcDate title={i18n.$intl('page.menuListPage.xxx').d('更新时间')} field="updatedAt" datetime width={175} editable={false}/>
      <PlcTextarea title={i18n.$intl('page.menuListPage.xxx').d('备注')} field="comment"/>
    </AutoTable>
  </>;
});
